<script type="text/javascript" charset="utf-8">
	//<![CDATA[

	var conditionsAccepted = false;
		var buttons;

		
		function onFBLoggedIn(){
			$(location).attr('href',"/login/fbconnect?fb_email=" + QP.FaceBookConnect.User.email);

			console.log("onFBLoggedIn");
			
		}

		function onFBLoggedOut(){
			console.log("onFBLoggedOut");
			$(".facebutton").show();
		}
		// execute your scripts when the DOM is ready. this is a good habit
		$(document).ready(function() {


			
			QP.FaceBookConnect.init(false,"#facebook-connect-button",onFBLoggedIn, onFBLoggedOut);
			// si hay un usuario cacheado
			if(QP.FaceBookConnect.User.getCachedUser()){
				$("#UserProfiles_full_name").val(QP.FaceBookConnect.User.name);
				$("#UserEmails_email").val(QP.FaceBookConnect.User.email);
				$("#fb_id").val(QP.FaceBookConnect.User.uid);
				//$("#facebookmessage").show();
			}

			// select all desired input fields and attach tooltips to them
			$(".form-tooltip [rel='tooltip']").tooltip({	
			
				onBeforeShow: function() {
					//console.log(this.getTip());
					if (this.getTip().html().indexOf('class="cierre"')<=-1) {
						this.getTip().append('<div class="cierre"/>');
					}
				},
				// place tooltip on the right edge
				position: "center right",
				// a little tweaking of the position
				// offset: [-2, 10],
				// use the built-in fadeIn/fadeOut effect
				effect: "toggle",
				// custom opacity setting
				opacity: 1.0		
			});

			
			$.tools.validator.localize("es",{
				'*' : 'Por favor corrige este valor',
				'[required]' : 'Por favor completa este campo obligatorio',
				':email' : 'Por favor introduce un email válido',
				':number' : 'Por favor introduce un valor numúrico',
				':url' : 'Por favor introduce una url válida',
				'[max]' : 'Por favor introduce un valor mayor a $1',
				'[min]' : 'Por favor introduce un valor menor a $1',
				'[data-equals]' : 'El valor no corresponde con el campo $1'			
			});
			
			$.tools.validator.fn("[data-equals]", function(input) {
				var name = input.attr("data-equals"),
			 	field = this.getInputs().filter("[name=" + name + "]"); 
				return input.val() == field.val() ? true : {
					es: "Los valores no son iguales",
					en: "The values are not equal"
				}; 
			});
			
			
			$(".form-validator").validator({			
				 message: '<div/>',
					lang: 'es',
					
					onSuccess:function(){
						ok=false;
						elems = document.getElementsByName('s3capcha');
						for(i=0;i<elems.length;i++){
							if(elems[i].checked){
								ok=true;
							}
						}
						 if(!ok){
						 	$('#error_capcha').fadeIn();
						 	return false;
						 }
				 		return true;
					},
					onFail:function(){
					setTimeout(function(){
						$(".error div.cierre").remove();
						if ($(".error").html().indexOf('class="cierre"')<=-1) {
							$('<div class="cierre"/>').insertAfter($('.error p'));
						}
					},2);
				}
			});
			
			$('#capcha').s3Capcha();

		
		$("#conditions").overlay({
			onBeforeLoad: function() {
				// grab wrapper element inside content
				var wrap = this.getOverlay().find(".contentWrap");
				// load the page specified in the trigger
				wrap.load(this.getTrigger().attr("href"));
			},
			// enmascara
			mask: {
				//color: '#000',
				loadSpeed: 200
				//opacity: 0.8
			},
			closeOnClick: false
		});


		buttons = $("#modal-win a").click(function(e) {
			conditionsAccepted = (buttons.index(this) === 0);
			$("#conditions_cbx").attr('checked', conditionsAccepted);
		});

		
	});


	/*	
		function save() {
			$("#saving").jqm().jqmShow(); 
			
			$.getJSON('/signup/save', {
				"consumer[email]" : $("#email").val(),
				"consumer[password]" : $("#password").val(),
				"consumer[password2]" : $("#password2").val(),
				"consumer[full_name]" : $("#full_name").val(),
				"consumer[mobile]" : $("#mobile").val(),
				"recaptcha_challenge_field" : $("#recaptcha_challenge_field").val(),
				"recaptcha_response_field" : $("#recaptcha_response_field").val()
			},
			function(result){

				//processResult(result, "/signup/emailsent?email=" + result.email, validator);
			  //Recaptcha.reload();
			});
		}

	*/
		
		
	</script>
	